import tensorflow as tf

a = tf.constant([1.0,2.0])
b = tf.constant([2.0,3.0])
#效果等同于  tf_add2 = tf.add(a,b)
tf_add = a + b 
print("tf_add:\n",tf_add)

@tf.function
def compute_add():
    return tf_add
print("addition with constants:",compute_add().numpy())

#在新的计算图中定义张量和操作
#grahic_a =tf.Graph()

@tf.function
def compute_mul(a,b):
    return tf.multiply(a,b)
print("mul with constants:",compute_mul(a,b).numpy())

a = tf.compat.v1.constant([3.0,4.0])
b = tf.compat.v1.constant([5.0,90.0])
tf_mul = compute_mul(a,b)
print("Grahic_a run:", tf_mul)

